﻿package Engine.RMI
{
    import Framework.Protocol.*;

    public class CommunicatorManager extends Object
    {
        private var _communicators:Array;
        private static var instance:CommunicatorManager;

        public function CommunicatorManager()
        {
            if (instance != null)
            {
                throw new Error("singler");
            }
            this._communicators = new Array();
            return;
        }// end function

        public function createCommunicator(param1:String, param2:IProtocol = null) : Communicator
        {
            var _loc_3:Communicator = null;
            var _loc_4:int = 0;
            while (_loc_4 < this._communicators.length)
            {
                
                _loc_3 = this._communicators[_loc_4] as Communicator;
                if (_loc_3.url == param1)
                {
                    return _loc_3;
                }
                _loc_4++;
            }
            _loc_3 = new Communicator(param2);
            _loc_3.url = param1;
            this._communicators.push(_loc_3);
            return _loc_3;
        }// end function

        public function removeCommunicator(param1:String) : Boolean
        {
            var _loc_2:Communicator = null;
            var _loc_3:int = 0;
            var _loc_4:Boolean = false;
            _loc_3 = 0;
            while (_loc_3 < this._communicators.length)
            {
                
                _loc_2 = this._communicators[_loc_3] as Communicator;
                if (_loc_2.url == param1)
                {
                    this._communicators.splice(_loc_3, 1);
                    _loc_4 = true;
                }
                _loc_3++;
            }
            return false;
        }// end function

        public static function getInstance() : CommunicatorManager
        {
            if (instance == null)
            {
                instance = new CommunicatorManager;
            }
            return instance;
        }// end function

    }
}
